<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>第 9 章 关于非线性拟合的初始值 | 使用 R 语言分析 LI-6400 和 LI-6800 光合仪的数据</title>
  <meta name="description" content="使用 R 语言分析 LI-6400XT 与 LI-6800 数据" />
  <meta name="generator" content="bookdown 0.24 and GitBook 2.6.7" />

  <meta property="og:title" content="第 9 章 关于非线性拟合的初始值 | 使用 R 语言分析 LI-6400 和 LI-6800 光合仪的数据" />
  <meta property="og:type" content="book" />
  
  <meta property="og:image" content="/images/coverpage.png" />
  <meta property="og:description" content="使用 R 语言分析 LI-6400XT 与 LI-6800 数据" />
  <meta name="github-repo" content="zhujiedong/photoanalysis" />

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="第 9 章 关于非线性拟合的初始值 | 使用 R 语言分析 LI-6400 和 LI-6800 光合仪的数据" />
  
  <meta name="twitter:description" content="使用 R 语言分析 LI-6400XT 与 LI-6800 数据" />
  <meta name="twitter:image" content="/images/coverpage.png" />

<meta name="author" content="祝介东    北京力高泰科技有限公司" />


<meta name="date" content="2021-11-12" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="lrc_fit.html"/>
<link rel="next" href="anay_6800.html"/>
<script src="libs/header-attrs-2.11/header-attrs.js"></script>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />








<link href="libs/anchor-sections-1.0.1/anchor-sections.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.0.1/anchor-sections.js"></script>


<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>

<style type="text/css">
/* Used with Pandoc 2.11+ new --citeproc when CSL is used */
div.csl-bib-body { }
div.csl-entry {
  clear: both;
}
.hanging div.csl-entry {
  margin-left:2em;
  text-indent:-2em;
}
div.csl-left-margin {
  min-width:2em;
  float:left;
}
div.csl-right-inline {
  margin-left:2em;
  padding-left:1em;
}
div.csl-indent {
  margin-left: 2em;
}
</style>

<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="./">R 软件与光合数据分析</a></li>

<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>欢迎</a></li>
<li class="chapter" data-level="" data-path="frontmatter.html"><a href="frontmatter.html"><i class="fa fa-check"></i>前言</a></li>
<li class="chapter" data-level="" data-path="copyright.html"><a href="copyright.html"><i class="fa fa-check"></i>版权</a></li>
<li class="chapter" data-level="1" data-path="intro.html"><a href="intro.html"><i class="fa fa-check"></i><b>1</b> R 软件与 Rstudio</a>
<ul>
<li class="chapter" data-level="1.1" data-path="intro.html"><a href="intro.html#rsoft"><i class="fa fa-check"></i><b>1.1</b> R 软件</a></li>
<li class="chapter" data-level="1.2" data-path="intro.html"><a href="intro.html#rstudiosoft"><i class="fa fa-check"></i><b>1.2</b> Rstudio</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="batch_question.html"><a href="batch_question.html"><i class="fa fa-check"></i><b>2</b> 批量处理光合测定数据</a>
<ul>
<li class="chapter" data-level="2.1" data-path="batch_question.html"><a href="batch_question.html#install_readphoto"><i class="fa fa-check"></i><b>2.1</b> 安装</a></li>
<li class="chapter" data-level="2.2" data-path="batch_question.html"><a href="batch_question.html#batch64"><i class="fa fa-check"></i><b>2.2</b> LI-6400 数据处理</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="batch_question.html"><a href="batch_question.html#li-6400-数据的整合6400combine"><i class="fa fa-check"></i><b>2.2.1</b> LI-6400 数据的整合{#6400combine}</a></li>
<li class="chapter" data-level="2.2.2" data-path="batch_question.html"><a href="batch_question.html#recompute6400"><i class="fa fa-check"></i><b>2.2.2</b> LI-6400 数据重计算</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="batch_question.html"><a href="batch_question.html#li-6800-数据的处理-6800data"><i class="fa fa-check"></i><b>2.3</b> LI-6800 数据的处理 {#6800data}</a>
<ul>
<li class="chapter" data-level="2.3.1" data-path="batch_question.html"><a href="batch_question.html#r-下-excel-格式读取的重计算-6800xlconnect"><i class="fa fa-check"></i><b>2.3.1</b> R 下 Excel 格式读取的重计算 {##6800xlconnect}</a></li>
<li class="chapter" data-level="2.3.2" data-path="batch_question.html"><a href="batch_question.html#python"><i class="fa fa-check"></i><b>2.3.2</b> 使用 Python 来处理</a></li>
<li class="chapter" data-level="2.3.3" data-path="batch_question.html"><a href="batch_question.html#python-r-batch"><i class="fa fa-check"></i><b>2.3.3</b> 批量处理 csv 文件</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="3" data-path="response_fit.html"><a href="response_fit.html"><i class="fa fa-check"></i><b>3</b> CO<sub>2</sub> 响应曲线的拟合</a>
<ul>
<li class="chapter" data-level="3.1" data-path="response_fit.html"><a href="response_fit.html#fvcb_mod"><i class="fa fa-check"></i><b>3.1</b> FvCB 模型</a></li>
<li class="chapter" data-level="3.2" data-path="response_fit.html"><a href="response_fit.html#co2_note"><i class="fa fa-check"></i><b>3.2</b> CO<sub>2</sub> 响应曲线测量的注意事项</a>
<ul>
<li class="chapter" data-level="3.2.1" data-path="response_fit.html"><a href="response_fit.html#model_3"><i class="fa fa-check"></i><b>3.2.1</b> 分段性</a></li>
<li class="chapter" data-level="3.2.2" data-path="response_fit.html"><a href="response_fit.html#note_detail"><i class="fa fa-check"></i><b>3.2.2</b> 测量注意事项</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="response_fit.html"><a href="response_fit.html#plantecophys"><i class="fa fa-check"></i><b>3.3</b> <code>plantecophys</code> 软件包</a></li>
<li class="chapter" data-level="3.4" data-path="response_fit.html"><a href="response_fit.html#fit6400"><i class="fa fa-check"></i><b>3.4</b> LI-6400XT CO<sub>2</sub> 响应曲线的拟合</a>
<ul>
<li class="chapter" data-level="3.4.1" data-path="response_fit.html"><a href="response_fit.html#fitaci_intro"><i class="fa fa-check"></i><b>3.4.1</b> fitaci 函数介绍</a></li>
</ul></li>
<li class="chapter" data-level="3.5" data-path="response_fit.html"><a href="response_fit.html#plantecophy_use"><i class="fa fa-check"></i><b>3.5</b> 使用 <code>plantecophys</code> 拟合 LI-6400XT CO<sub>2</sub> 响应曲线数据</a>
<ul>
<li class="chapter" data-level="3.5.1" data-path="response_fit.html"><a href="response_fit.html#data6400"><i class="fa fa-check"></i><b>3.5.1</b> 数据的前处理</a></li>
<li class="chapter" data-level="3.5.2" data-path="response_fit.html"><a href="response_fit.html#fitaci-p"><i class="fa fa-check"></i><b>3.5.2</b> 使用示例</a></li>
<li class="chapter" data-level="3.5.3" data-path="response_fit.html"><a href="response_fit.html#onpoint_fit"><i class="fa fa-check"></i><b>3.5.3</b> 使用 ‘onepoint’ 单独计算 V<sub>cmax</sub> 和 J<sub>max</sub></a></li>
<li class="chapter" data-level="3.5.4" data-path="response_fit.html"><a href="response_fit.html#multi_curve"><i class="fa fa-check"></i><b>3.5.4</b> 多条 CO<sub>2</sub> 响应曲线的拟合</a></li>
<li class="chapter" data-level="3.5.5" data-path="response_fit.html"><a href="response_fit.html#transition"><i class="fa fa-check"></i><b>3.5.5</b> <code>findCiTransition</code> 函数</a></li>
</ul></li>
<li class="chapter" data-level="3.6" data-path="response_fit.html"><a href="response_fit.html#c4"><i class="fa fa-check"></i><b>3.6</b> C4 植物光合</a>
<ul>
<li class="chapter" data-level="3.6.1" data-path="response_fit.html"><a href="response_fit.html#c4_sim"><i class="fa fa-check"></i><b>3.6.1</b> C4 植物光合速率的计算</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="4" data-path="stomotal_sim.html"><a href="stomotal_sim.html"><i class="fa fa-check"></i><b>4</b> 气孔导度模型的拟合</a>
<ul>
<li class="chapter" data-level="4.1" data-path="stomotal_sim.html"><a href="stomotal_sim.html#ballberry"><i class="fa fa-check"></i><b>4.1</b> BallBerry 模型</a></li>
<li class="chapter" data-level="4.2" data-path="stomotal_sim.html"><a href="stomotal_sim.html#bbleuning"><i class="fa fa-check"></i><b>4.2</b> BBLeuning 模型</a></li>
<li class="chapter" data-level="4.3" data-path="stomotal_sim.html"><a href="stomotal_sim.html#bboptifull"><i class="fa fa-check"></i><b>4.3</b> BBOptiFull 模型</a></li>
<li class="chapter" data-level="4.4" data-path="stomotal_sim.html"><a href="stomotal_sim.html#fitbb-p"><i class="fa fa-check"></i><b>4.4</b> <code>fitBB</code> 函数</a></li>
<li class="chapter" data-level="4.5" data-path="stomotal_sim.html"><a href="stomotal_sim.html#fitbbs"><i class="fa fa-check"></i><b>4.5</b> <code>fitBBs</code> 函数</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="stomotal_couple.html"><a href="stomotal_couple.html"><i class="fa fa-check"></i><b>5</b> 光合最优气孔导度耦合模型</a>
<ul>
<li class="chapter" data-level="5.1" data-path="stomotal_couple.html"><a href="stomotal_couple.html#farao"><i class="fa fa-check"></i><b>5.1</b> <code>FARAO</code> 函数</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="photo_stomo.html"><a href="photo_stomo.html"><i class="fa fa-check"></i><b>6</b> 光合气孔导度耦合模型</a>
<ul>
<li class="chapter" data-level="6.1" data-path="photo_stomo.html"><a href="photo_stomo.html#photosyn"><i class="fa fa-check"></i><b>6.1</b> <code>Photosyn</code> 函数</a>
<ul>
<li class="chapter" data-level="6.1.1" data-path="photo_stomo.html"><a href="photo_stomo.html#photo_exam"><i class="fa fa-check"></i><b>6.1.1</b> <code>Photosyn</code> 使用举例</a></li>
</ul></li>
<li class="chapter" data-level="6.2" data-path="photo_stomo.html"><a href="photo_stomo.html#photsyneb"><i class="fa fa-check"></i><b>6.2</b> <code>PhotosynEB</code> 函数</a></li>
<li class="chapter" data-level="6.3" data-path="photo_stomo.html"><a href="photo_stomo.html#photosyntuzet"><i class="fa fa-check"></i><b>6.3</b> <code>PhotosynTuzet</code> 函数</a>
<ul>
<li class="chapter" data-level="6.3.1" data-path="photo_stomo.html"><a href="photo_stomo.html#photosyntuzet_para"><i class="fa fa-check"></i><b>6.3.1</b> <code>PhotosynTuzet</code> 的参数</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="7" data-path="rhtovpd.html"><a href="rhtovpd.html"><i class="fa fa-check"></i><b>7</b> RHtoVPD 函数</a></li>
<li class="chapter" data-level="8" data-path="lrc_fit.html"><a href="lrc_fit.html"><i class="fa fa-check"></i><b>8</b> 光响应曲线的拟合</a>
<ul>
<li class="chapter" data-level="8.1" data-path="lrc_fit.html"><a href="lrc_fit.html#rec_mod"><i class="fa fa-check"></i><b>8.1</b> 直角双曲线模型</a>
<ul>
<li class="chapter" data-level="8.1.1" data-path="lrc_fit.html"><a href="lrc_fit.html#rec_fit"><i class="fa fa-check"></i><b>8.1.1</b> 直角双曲线模型的实现</a></li>
</ul></li>
<li class="chapter" data-level="8.2" data-path="lrc_fit.html"><a href="lrc_fit.html#nonrec-mod"><i class="fa fa-check"></i><b>8.2</b> 非直角双曲线模型</a>
<ul>
<li class="chapter" data-level="8.2.1" data-path="lrc_fit.html"><a href="lrc_fit.html#nonrec_mode_exam"><i class="fa fa-check"></i><b>8.2.1</b> 非直角双曲线模型的实现</a></li>
</ul></li>
<li class="chapter" data-level="8.3" data-path="lrc_fit.html"><a href="lrc_fit.html#lrc_exp"><i class="fa fa-check"></i><b>8.3</b> 指数模型</a>
<ul>
<li class="chapter" data-level="8.3.1" data-path="lrc_fit.html"><a href="lrc_fit.html#lrc_exp_exam"><i class="fa fa-check"></i><b>8.3.1</b> 指数模型的实现</a></li>
</ul></li>
<li class="chapter" data-level="8.4" data-path="lrc_fit.html"><a href="lrc_fit.html#rev_rec"><i class="fa fa-check"></i><b>8.4</b> 直角双曲线的修正模型</a>
<ul>
<li class="chapter" data-level="8.4.1" data-path="lrc_fit.html"><a href="lrc_fit.html#rev_rec_exam"><i class="fa fa-check"></i><b>8.4.1</b> 直角双曲线修正模型的实现</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="9" data-path="start_con.html"><a href="start_con.html"><i class="fa fa-check"></i><b>9</b> 关于非线性拟合的初始值</a>
<ul>
<li class="chapter" data-level="9.1" data-path="start_con.html"><a href="start_con.html#nlslm"><i class="fa fa-check"></i><b>9.1</b> nlsLM 解决方案</a></li>
<li class="chapter" data-level="9.2" data-path="start_con.html"><a href="start_con.html#plot_comp"><i class="fa fa-check"></i><b>9.2</b> 作图比对法</a>
<ul>
<li class="chapter" data-level="9.2.1" data-path="start_con.html"><a href="start_con.html#plot_exam"><i class="fa fa-check"></i><b>9.2.1</b> 实现过程</a></li>
<li class="chapter" data-level="9.2.2" data-path="start_con.html"><a href="start_con.html#show_demo"><i class="fa fa-check"></i><b>9.2.2</b> 直观展示</a></li>
</ul></li>
<li class="chapter" data-level="9.3" data-path="start_con.html"><a href="start_con.html#mult_try"><i class="fa fa-check"></i><b>9.3</b> 自动多次尝试法</a></li>
<li class="chapter" data-level="9.4" data-path="start_con.html"><a href="start_con.html#sum_start"><i class="fa fa-check"></i><b>9.4</b> 小结</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="anay_6800.html"><a href="anay_6800.html"><i class="fa fa-check"></i><b>10</b> LI-6800 的数据分析</a>
<ul>
<li class="chapter" data-level="10.1" data-path="anay_6800.html"><a href="anay_6800.html#data6800"><i class="fa fa-check"></i><b>10.1</b> 数据格式</a></li>
<li class="chapter" data-level="10.2" data-path="anay_6800.html"><a href="anay_6800.html#dif"><i class="fa fa-check"></i><b>10.2</b> LI-6800 与 LI-6400 使用时的差别</a></li>
<li class="chapter" data-level="10.3" data-path="anay_6800.html"><a href="anay_6800.html#notice"><i class="fa fa-check"></i><b>10.3</b> 光响应曲线注意事项</a></li>
<li class="chapter" data-level="10.4" data-path="anay_6800.html"><a href="anay_6800.html#other_light_response"><i class="fa fa-check"></i><b>10.4</b> 其他软件包的光响应曲线</a></li>
<li class="chapter" data-level="10.5" data-path="anay_6800.html"><a href="anay_6800.html#racir68"><i class="fa fa-check"></i><b>10.5</b> LI-6800 RACiR的测量与拟合</a></li>
<li class="chapter" data-level="10.6" data-path="anay_6800.html"><a href="anay_6800.html#racir-conifer"><i class="fa fa-check"></i><b>10.6</b> LI-6800 RACiR簇状叶的测量与拟合</a></li>
<li class="chapter" data-level="10.7" data-path="anay_6800.html"><a href="anay_6800.html#multi1"><i class="fa fa-check"></i><b>10.7</b> 多个速率的 RACiR 曲线研究</a>
<ul>
<li class="chapter" data-level="10.7.1" data-path="anay_6800.html"><a href="anay_6800.html#multi2"><i class="fa fa-check"></i><b>10.7.1</b> 光呼吸滞后模型</a></li>
<li class="chapter" data-level="10.7.2" data-path="anay_6800.html"><a href="anay_6800.html#code-photoresp"><i class="fa fa-check"></i><b>10.7.2</b> 光呼吸滞后性代码</a></li>
<li class="chapter" data-level="10.7.3" data-path="anay_6800.html"><a href="anay_6800.html#multi4"><i class="fa fa-check"></i><b>10.7.3</b> 数据的构造</a></li>
<li class="chapter" data-level="10.7.4" data-path="anay_6800.html"><a href="anay_6800.html#multi5"><i class="fa fa-check"></i><b>10.7.4</b> 光呼吸滞后性作图</a></li>
<li class="chapter" data-level="10.7.5" data-path="anay_6800.html"><a href="anay_6800.html#multi6"><i class="fa fa-check"></i><b>10.7.5</b> 补偿点计算</a></li>
<li class="chapter" data-level="10.7.6" data-path="anay_6800.html"><a href="anay_6800.html#multi7"><i class="fa fa-check"></i><b>10.7.6</b> 无光呼吸酶失活模块</a></li>
<li class="chapter" data-level="10.7.7" data-path="anay_6800.html"><a href="anay_6800.html#multi9"><i class="fa fa-check"></i><b>10.7.7</b> 酶失活作图</a></li>
<li class="chapter" data-level="10.7.8" data-path="anay_6800.html"><a href="anay_6800.html#multi10"><i class="fa fa-check"></i><b>10.7.8</b> 不同失活程度下补偿点计算</a></li>
</ul></li>
<li class="chapter" data-level="10.8" data-path="anay_6800.html"><a href="anay_6800.html#multi11"><i class="fa fa-check"></i><b>10.8</b> 时间延迟的扩散限制</a>
<ul>
<li class="chapter" data-level="10.8.1" data-path="anay_6800.html"><a href="anay_6800.html#multi12"><i class="fa fa-check"></i><b>10.8.1</b> 扩散限制滞后性</a></li>
</ul></li>
<li class="chapter" data-level="10.9" data-path="anay_6800.html"><a href="anay_6800.html#multi13"><i class="fa fa-check"></i><b>10.9</b> 扩散限制作图</a>
<ul>
<li class="chapter" data-level="10.9.1" data-path="anay_6800.html"><a href="anay_6800.html#multi14"><i class="fa fa-check"></i><b>10.9.1</b> 补偿点的计算</a></li>
<li class="chapter" data-level="10.9.2" data-path="anay_6800.html"><a href="anay_6800.html#multi15"><i class="fa fa-check"></i><b>10.9.2</b> 所有图形代码</a></li>
</ul></li>
<li class="chapter" data-level="10.10" data-path="anay_6800.html"><a href="anay_6800.html#fluro68"><i class="fa fa-check"></i><b>10.10</b> LI-6800 荧光数据分析</a>
<ul>
<li class="chapter" data-level="10.10.1" data-path="anay_6800.html"><a href="anay_6800.html#jiptest"><i class="fa fa-check"></i><b>10.10.1</b> jip test 的实现</a></li>
<li class="chapter" data-level="10.10.2" data-path="anay_6800.html"><a href="anay_6800.html#jiptest_pack"><i class="fa fa-check"></i><b>10.10.2</b> <code>jiptest</code> 软件包安装</a></li>
<li class="chapter" data-level="10.10.3" data-path="anay_6800.html"><a href="anay_6800.html#readfluor"><i class="fa fa-check"></i><b>10.10.3</b> <code>read_files</code> 及 <code>read_dcfiles</code> 函数</a></li>
<li class="chapter" data-level="10.10.4" data-path="anay_6800.html"><a href="anay_6800.html#testfluor"><i class="fa fa-check"></i><b>10.10.4</b> <code>jip_test</code> 及 <code>jip_dctest</code> 函数</a></li>
<li class="chapter" data-level="10.10.5" data-path="anay_6800.html"><a href="anay_6800.html#plotfluor"><i class="fa fa-check"></i><b>10.10.5</b> 图像查看函数</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="11" data-path="big-leaf.html"><a href="big-leaf.html"><i class="fa fa-check"></i><b>11</b> 大叶模型</a>
<ul>
<li class="chapter" data-level="11.1" data-path="big-leaf.html"><a href="big-leaf.html#leaf-scale-meas"><i class="fa fa-check"></i><b>11.1</b> 叶片尺度测量</a></li>
<li class="chapter" data-level="11.2" data-path="big-leaf.html"><a href="big-leaf.html#big-leaf-data"><i class="fa fa-check"></i><b>11.2</b> 数据的处理</a>
<ul>
<li class="chapter" data-level="11.2.1" data-path="big-leaf.html"><a href="big-leaf.html#single-data-big-leaf"><i class="fa fa-check"></i><b>11.2.1</b> 单个测量数据的处理</a></li>
<li class="chapter" data-level="11.2.2" data-path="big-leaf.html"><a href="big-leaf.html#big-leaf-data-MODEL"><i class="fa fa-check"></i><b>11.2.2</b> 大叶模型的数据处理</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="12" data-path="pca-anylysis.html"><a href="pca-anylysis.html"><i class="fa fa-check"></i><b>12</b> 大话 PCA</a>
<ul>
<li class="chapter" data-level="12.1" data-path="pca-anylysis.html"><a href="pca-anylysis.html#geom-pca"><i class="fa fa-check"></i><b>12.1</b> 几何解释</a></li>
<li class="chapter" data-level="12.2" data-path="pca-anylysis.html"><a href="pca-anylysis.html#alge-pca"><i class="fa fa-check"></i><b>12.2</b> 线性代数解释</a>
<ul>
<li class="chapter" data-level="12.2.1" data-path="pca-anylysis.html"><a href="pca-anylysis.html#egi-pca"><i class="fa fa-check"></i><b>12.2.1</b> 特征向量与特征值</a></li>
<li class="chapter" data-level="12.2.2" data-path="pca-anylysis.html"><a href="pca-anylysis.html#man_pca"><i class="fa fa-check"></i><b>12.2.2</b> 手动实现过程</a></li>
<li class="chapter" data-level="12.2.3" data-path="pca-anylysis.html"><a href="pca-anylysis.html#prcom"><i class="fa fa-check"></i><b>12.2.3</b> <code>prcomp</code> 的实现</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="13" data-path="sessioninfo.html"><a href="sessioninfo.html"><i class="fa fa-check"></i><b>13</b> 环境与配置</a></li>
<li class="chapter" data-level="" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i>参考文献</a></li>
<li class="divider"></li>
<li><a href="https://bookdown.org" target="blank">由 bookdown 驱动</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">使用 R 语言分析 LI-6400 和 LI-6800 光合仪的数据</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="start_con" class="section level1" number="9">
<h1><span class="header-section-number">第 9 章</span> 关于非线性拟合的初始值</h1>
<p>在解释初始值之前我们首先需要了解一个数学上的概念——迭代，</p>
<blockquote>
<p>“迭代法”也称“辗转法”是一种不断用变量的旧值递推新值的过程。</p>
</blockquote>
<p>用通俗但不是特别严谨的说法可解释为：每次执行这种算法时，程序都会从原值（也就是我抄的上面迭代法定义的旧值）推出一个新值。</p>
<p>之所以先介绍这个迭代，原因很简单，非线性拟合就是通过迭代的方法，需要对每一个变量<strong>最初的估计值进行不断的迭代，得到一个向一个点收缩或汇聚的值，这个估计值必须在实际值的一定范围内，程序通过不断调整这个值来改善拟合结果</strong>。这就解释了上面的问题，初始值是让程序开始运行的前提，不然没法迭代，必须设定。我下面的内容将以 LI-6800 的光响应曲线的测试数据，使用非直角双曲线模型进行拟合来讲解具体的 R 中的一些实现方法，我们首先导入数据，然后再利用这些数据逐个举例不同的确定初始值的方式。</p>
<div class="sourceCode" id="cb86"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb86-1"><a href="start_con.html#cb86-1" aria-hidden="true" tabindex="-1"></a>nls <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">&quot;data/nlstest.csv&quot;</span>)</span>
<span id="cb86-2"><a href="start_con.html#cb86-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb86-3"><a href="start_con.html#cb86-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb86-4"><a href="start_con.html#cb86-4" aria-hidden="true" tabindex="-1"></a><span class="co"># 光响应曲线比较简单，我们将需要的数据直接提取，方便后面操作</span></span>
<span id="cb86-5"><a href="start_con.html#cb86-5" aria-hidden="true" tabindex="-1"></a>lrc_Q <span class="ot">&lt;-</span> nls<span class="sc">$</span>Qin</span>
<span id="cb86-6"><a href="start_con.html#cb86-6" aria-hidden="true" tabindex="-1"></a>lrc_A <span class="ot">&lt;-</span> nls<span class="sc">$</span>A</span></code></pre></div>
<div id="nlslm" class="section level2" number="9.1">
<h2><span class="header-section-number">9.1</span> nlsLM 解决方案</h2>
<p>nlsLM 来自于 <span class="citation">Elzhov et al. (<a href="#ref-Elzhov2016minpack" role="doc-biblioref">2016</a>)</span> 的 <code>minpack.lm</code>，利用 C 语言的 MINPACK 库，修改了 Levenberg-Marquardt 算法，在实际操作中，很多时候并不准确的输入初始值，他也能得出比较好的拟合结果。但结果未必完美，出现下面让人烦恼的报错：</p>
<blockquote>
<p>singular gradient matrix at initial parameter estimates</p>
</blockquote>
<p>的概率会大大降低，而且尽管结果不如意，我们也可以利用他的结果缩小初始值的范围，继续尝试其他初始值。</p>
<p>例如下面的例子中，非直角双曲线的 Rd 的初始值我们可以利用暗呼吸的实测值大致估计，同理最大光合速率也是如此，剩下的分别为非直角双曲线曲率，我们暂定为 1，alpha 也暂定为 0.1，使用 <code>nlsLM</code> 进行拟合，结果如下：</p>
<div class="sourceCode" id="cb87"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb87-1"><a href="start_con.html#cb87-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(minpack.lm)</span>
<span id="cb87-2"><a href="start_con.html#cb87-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb87-3"><a href="start_con.html#cb87-3" aria-hidden="true" tabindex="-1"></a>lrcnls_lm <span class="ot">&lt;-</span> <span class="fu">nlsLM</span>(lrc_A <span class="sc">~</span> (<span class="dv">1</span><span class="sc">/</span>(<span class="dv">2</span><span class="sc">*</span>theta))<span class="sc">*</span></span>
<span id="cb87-4"><a href="start_con.html#cb87-4" aria-hidden="true" tabindex="-1"></a>        (alpha<span class="sc">*</span>lrc_Q<span class="sc">+</span>Am<span class="sc">-</span><span class="fu">sqrt</span>((alpha<span class="sc">*</span>lrc_Q<span class="sc">+</span>Am)<span class="sc">^</span><span class="dv">2</span> <span class="sc">-</span> </span>
<span id="cb87-5"><a href="start_con.html#cb87-5" aria-hidden="true" tabindex="-1"></a>        <span class="dv">4</span><span class="sc">*</span>alpha<span class="sc">*</span>theta<span class="sc">*</span>Am<span class="sc">*</span>lrc_Q))<span class="sc">-</span> </span>
<span id="cb87-6"><a href="start_con.html#cb87-6" aria-hidden="true" tabindex="-1"></a>        Rd, <span class="at">start=</span><span class="fu">list</span>(<span class="at">Am=</span>(<span class="fu">max</span>(lrc_A)<span class="sc">-</span><span class="fu">min</span>(lrc_A)),</span>
<span id="cb87-7"><a href="start_con.html#cb87-7" aria-hidden="true" tabindex="-1"></a>        <span class="at">alpha=</span><span class="fl">0.1</span>,<span class="at">Rd=</span><span class="sc">-</span><span class="fu">min</span>(lrc_A),<span class="at">theta=</span><span class="fl">0.8</span>)) </span></code></pre></div>
<p>结果没有报错，看上去没有问题，那我们观察一下具体的拟合结果：</p>
<div class="sourceCode" id="cb88"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb88-1"><a href="start_con.html#cb88-1" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(lrcnls_lm)</span></code></pre></div>
<pre><code>## 
## Formula: lrc_A ~ (1/(2 * theta)) * (alpha * lrc_Q + Am - sqrt((alpha * 
##     lrc_Q + Am)^2 - 4 * alpha * theta * Am * lrc_Q)) - Rd
## 
## Parameters:
##        Estimate Std. Error t value Pr(&gt;|t|)    
## Am    12.307570   0.406739  30.259 2.30e-10 ***
## alpha  0.045706   0.003423  13.352 3.09e-07 ***
## Rd     0.656638   0.132646   4.950 0.000791 ***
## theta  0.707522   0.079738   8.873 9.59e-06 ***
## ---
## Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Residual standard error: 0.1852 on 9 degrees of freedom
## 
## Number of iterations to convergence: 8 
## Achieved convergence tolerance: 1.49e-08</code></pre>
<p>结果看上去还可以<a href="references.html#fn14" class="footnote-ref" id="fnref14"><sup>14</sup></a>。</p>
</div>
<div id="plot_comp" class="section level2" number="9.2">
<h2><span class="header-section-number">9.2</span> 作图比对法</h2>
<p>模型很多参数可以用已有数据去估计，我们可以只来分析难以判断的参数，流程如下：</p>
<ul>
<li>Rd、Am等我们可以利用测量值来确定一个范围。</li>
<li>剩余的参数，我们也可以根据经验或文献来有一个大致的判断。</li>
<li>然后我们根据数学的方式来判断哪个参数对曲线形状影响最大（例如在分母上的参数，或者是乘以该参数，该参数可以显著改变计算结果，例如整体乘以或除以 0.1 还是 0.01，像 Rd 之类的参数本身就很小，多数公式中都是减去该值，对结果影响很小，我们通常直接使用实测值 ）。</li>
<li>将该参数取一系列值带入模型来求解净光合速率。</li>
<li>将计算的A值与光强进行作图，看我们计算的曲线与测量数据点的重合程度，必要时在修改其他参数，使曲线和散点重合度最好，重合程度最高的参数值即为我们需要的初始值。</li>
</ul>
<div id="plot_exam" class="section level3" number="9.2.1">
<h3><span class="header-section-number">9.2.1</span> 实现过程</h3>
<div class="sourceCode" id="cb90"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb90-1"><a href="start_con.html#cb90-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 我们选择的模型，将其写为一个函数，用于计算净光合速率</span></span>
<span id="cb90-2"><a href="start_con.html#cb90-2" aria-hidden="true" tabindex="-1"></a>expfct <span class="ot">&lt;-</span> <span class="cf">function</span>(x, Am, alpha, Rd, theta) {</span>
<span id="cb90-3"><a href="start_con.html#cb90-3" aria-hidden="true" tabindex="-1"></a>  (<span class="dv">1</span><span class="sc">/</span>(<span class="dv">2</span> <span class="sc">*</span> theta)) <span class="sc">*</span> (alpha <span class="sc">*</span> x <span class="sc">+</span> Am <span class="sc">-</span> </span>
<span id="cb90-4"><a href="start_con.html#cb90-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">sqrt</span>((alpha <span class="sc">*</span> x <span class="sc">+</span> Am)<span class="sc">^</span><span class="dv">2</span> <span class="sc">-</span> <span class="dv">4</span> <span class="sc">*</span> alpha <span class="sc">*</span> theta <span class="sc">*</span> Am <span class="sc">*</span> x)) <span class="sc">-</span> Rd</span>
<span id="cb90-5"><a href="start_con.html#cb90-5" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb90-6"><a href="start_con.html#cb90-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb90-7"><a href="start_con.html#cb90-7" aria-hidden="true" tabindex="-1"></a><span class="co"># 我们的数据</span></span>
<span id="cb90-8"><a href="start_con.html#cb90-8" aria-hidden="true" tabindex="-1"></a>test <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">x =</span> lrc_Q, <span class="at">y =</span> lrc_A)</span></code></pre></div>
<div class="sourceCode" id="cb91"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb91-1"><a href="start_con.html#cb91-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 先做实测数据的散点图</span></span>
<span id="cb91-2"><a href="start_con.html#cb91-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(y <span class="sc">~</span> x, <span class="at">data =</span> test)</span>
<span id="cb91-3"><a href="start_con.html#cb91-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb91-4"><a href="start_con.html#cb91-4" aria-hidden="true" tabindex="-1"></a><span class="co"># 利用上面的函数，假定 alpha 的值为0.8，看计算值与测量值重合程度</span></span>
<span id="cb91-5"><a href="start_con.html#cb91-5" aria-hidden="true" tabindex="-1"></a><span class="fu">curve</span>(<span class="fu">expfct</span>(x, <span class="at">Am =</span> (<span class="fu">max</span>(lrc_A)<span class="sc">-</span><span class="fu">min</span>(lrc_A)),</span>
<span id="cb91-6"><a href="start_con.html#cb91-6" aria-hidden="true" tabindex="-1"></a>     <span class="at">alpha=</span><span class="fl">0.8</span>, <span class="at">Rd=</span><span class="sc">-</span><span class="fu">min</span>(lrc_A), <span class="at">theta=</span><span class="fl">0.8</span>), <span class="at">add =</span> <span class="cn">TRUE</span></span>
<span id="cb91-7"><a href="start_con.html#cb91-7" aria-hidden="true" tabindex="-1"></a>             )</span></code></pre></div>
<div class="figure"><span style="display:block;" id="fig:pomp"></span>
<img src="bookdown_files/figure-html/pomp-1.png" alt="初步判断 alpha 的初始值" width="672" />
<p class="caption">
图 9.1: 初步判断 alpha 的初始值
</p>
</div>
<p>观察上图 <a href="start_con.html#fig:pomp">9.1</a> 的结果可以看到，曲线在 0-600 的范围内，拟合值明显偏大，观察模型的方程式，以及其他起始值的设定方式，我们初步判断 alpha 的值偏大，于是乎我们将其改小观察，观察曲线和测量点的重合仍然不是很好，我们尝试修改 theta 值与 alpha 值（也即曲线高于测量点，则需要减小纵坐标的值，低于测量点，则需要增加该值，该过程省略，我大概设置了五分钟完成），最终得出的结果如下：</p>
<div class="sourceCode" id="cb92"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb92-1"><a href="start_con.html#cb92-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(y <span class="sc">~</span> x, <span class="at">data =</span> test)</span>
<span id="cb92-2"><a href="start_con.html#cb92-2" aria-hidden="true" tabindex="-1"></a><span class="fu">curve</span>(<span class="fu">expfct</span>(x, <span class="at">Am =</span> (<span class="fu">max</span>(lrc_A)<span class="sc">-</span><span class="fu">min</span>(lrc_A)),</span>
<span id="cb92-3"><a href="start_con.html#cb92-3" aria-hidden="true" tabindex="-1"></a>     <span class="at">alpha=</span><span class="fl">0.06</span>, <span class="at">Rd=</span><span class="sc">-</span><span class="fu">min</span>(lrc_A), <span class="at">theta=</span><span class="fl">0.82</span>), <span class="at">add =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<div class="figure"><span style="display:block;" id="fig:alpp"></span>
<img src="bookdown_files/figure-html/alpp-1.png" alt="初修正后断 alpha 的初始值" width="672" />
<p class="caption">
图 9.2: 初修正后断 alpha 的初始值
</p>
</div>
<p>图 <a href="start_con.html#fig:alpp">9.2</a> 尽管看上去效果仍然不满意，但我们可试着进行拟合，看能否得到显著差异的结果：</p>
<div class="sourceCode" id="cb93"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb93-1"><a href="start_con.html#cb93-1" aria-hidden="true" tabindex="-1"></a>lrcnls_manual <span class="ot">&lt;-</span> <span class="fu">nls</span>(lrc_A <span class="sc">~</span> </span>
<span id="cb93-2"><a href="start_con.html#cb93-2" aria-hidden="true" tabindex="-1"></a>        (<span class="dv">1</span><span class="sc">/</span>(<span class="dv">2</span><span class="sc">*</span>theta))<span class="sc">*</span></span>
<span id="cb93-3"><a href="start_con.html#cb93-3" aria-hidden="true" tabindex="-1"></a>        (alpha<span class="sc">*</span>lrc_Q<span class="sc">+</span>Am<span class="sc">-</span><span class="fu">sqrt</span>((alpha<span class="sc">*</span>lrc_Q<span class="sc">+</span>Am)<span class="sc">^</span><span class="dv">2</span> <span class="sc">-</span> </span>
<span id="cb93-4"><a href="start_con.html#cb93-4" aria-hidden="true" tabindex="-1"></a>                               <span class="dv">4</span><span class="sc">*</span>alpha<span class="sc">*</span>theta<span class="sc">*</span>Am<span class="sc">*</span>lrc_Q))<span class="sc">-</span> </span>
<span id="cb93-5"><a href="start_con.html#cb93-5" aria-hidden="true" tabindex="-1"></a>        Rd, <span class="at">start=</span><span class="fu">list</span>(<span class="at">Am=</span>(<span class="fu">max</span>(lrc_A)<span class="sc">-</span><span class="fu">min</span>(lrc_A)),</span>
<span id="cb93-6"><a href="start_con.html#cb93-6" aria-hidden="true" tabindex="-1"></a>                       <span class="at">alpha=</span><span class="fl">0.03</span>,<span class="at">Rd=</span><span class="sc">-</span><span class="fu">min</span>(lrc_A),<span class="at">theta=</span><span class="fl">0.6</span>))</span>
<span id="cb93-7"><a href="start_con.html#cb93-7" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(lrcnls_manual)</span></code></pre></div>
<pre><code>## 
## Formula: lrc_A ~ (1/(2 * theta)) * (alpha * lrc_Q + Am - sqrt((alpha * 
##     lrc_Q + Am)^2 - 4 * alpha * theta * Am * lrc_Q)) - Rd
## 
## Parameters:
##        Estimate Std. Error t value Pr(&gt;|t|)    
## Am    12.307585   0.406741  30.259 2.30e-10 ***
## alpha  0.045706   0.003423  13.352 3.09e-07 ***
## Rd     0.656642   0.132646   4.950 0.000791 ***
## theta  0.707518   0.079739   8.873 9.59e-06 ***
## ---
## Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Residual standard error: 0.1852 on 9 degrees of freedom
## 
## Number of iterations to convergence: 7 
## Achieved convergence tolerance: 4.601e-06</code></pre>
<div class="sourceCode" id="cb95"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb95-1"><a href="start_con.html#cb95-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 对拟合之后的结果作图，观察使用我们的估计值，</span></span>
<span id="cb95-2"><a href="start_con.html#cb95-2" aria-hidden="true" tabindex="-1"></a><span class="co"># 迭代的最终值与元数据的重合程度</span></span>
<span id="cb95-3"><a href="start_con.html#cb95-3" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(y <span class="sc">~</span> x, <span class="at">data =</span> test, <span class="at">ylim =</span> <span class="fu">c</span>(<span class="sc">-</span><span class="dv">2</span>, <span class="dv">14</span>))</span>
<span id="cb95-4"><a href="start_con.html#cb95-4" aria-hidden="true" tabindex="-1"></a><span class="fu">curve</span>(<span class="fu">expfct</span>(x, <span class="at">Am =</span> <span class="fl">12.307586</span>,</span>
<span id="cb95-5"><a href="start_con.html#cb95-5" aria-hidden="true" tabindex="-1"></a>     <span class="at">alpha=</span><span class="fl">0.045706</span>, <span class="at">Rd=</span> <span class="fl">0.656643</span>, <span class="at">theta=</span><span class="fl">0.707518</span>), <span class="at">add =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<div class="figure"><span style="display:block;" id="fig:alpf"></span>
<img src="bookdown_files/figure-html/alpf-1.png" alt="检验作图法的初始值判断" width="672" />
<p class="caption">
图 9.3: 检验作图法的初始值判断
</p>
</div>
<p>从 <a href="start_con.html#fig:alpf">9.3</a> 的呈现以及 F 检验的 p 值来讲，图形已经比较完美了。<strong>也就是说尽管我们作图的时候看到重合度并不高，但是非线性拟合本来就是一个迭代的过程，只要我们的数据与真实值相差不大，还是能够得到完美结果的</strong>。</p>
</div>
<div id="show_demo" class="section level3" number="9.2.2">
<h3><span class="header-section-number">9.2.2</span> 直观展示</h3>
<p>上面的表述太啰嗦，直接用下面的图形说明一下，其中 alhpa 的取值在此处选择从 0.01 到 0.07，每次增加 0.05，其他值分别为 Am = 12.31, Rd= 0.66, theta=0.71 （此处为展示效果和方便，将这些值直接按照拟合结果设定了，实际差别不大）</p>
<div class="sourceCode" id="cb96"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb96-1"><a href="start_con.html#cb96-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb96-2"><a href="start_con.html#cb96-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(purrr)</span>
<span id="cb96-3"><a href="start_con.html#cb96-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-4"><a href="start_con.html#cb96-4" aria-hidden="true" tabindex="-1"></a>lrc <span class="ot">&lt;-</span> <span class="fu">read.csv</span>(<span class="st">&quot;data/nlstest.csv&quot;</span>)</span>
<span id="cb96-5"><a href="start_con.html#cb96-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-6"><a href="start_con.html#cb96-6" aria-hidden="true" tabindex="-1"></a><span class="co"># 光响应曲线比较简单，我们将需要的数据直接提取，方便后面操作</span></span>
<span id="cb96-7"><a href="start_con.html#cb96-7" aria-hidden="true" tabindex="-1"></a>lrc_Q <span class="ot">&lt;-</span> lrc<span class="sc">$</span>Qin</span>
<span id="cb96-8"><a href="start_con.html#cb96-8" aria-hidden="true" tabindex="-1"></a>lrc_A <span class="ot">&lt;-</span> lrc<span class="sc">$</span>A</span>
<span id="cb96-9"><a href="start_con.html#cb96-9" aria-hidden="true" tabindex="-1"></a>n <span class="ot">&lt;-</span> <span class="fu">length</span>(lrc_A)</span>
<span id="cb96-10"><a href="start_con.html#cb96-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-11"><a href="start_con.html#cb96-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-12"><a href="start_con.html#cb96-12" aria-hidden="true" tabindex="-1"></a>alp <span class="ot">&lt;-</span> <span class="fu">paste0</span>(<span class="st">&quot;a=&quot;</span>, <span class="fu">seq</span>(<span class="fl">0.01</span>, <span class="fl">0.07</span>, <span class="at">by =</span> <span class="fl">0.005</span>))</span>
<span id="cb96-13"><a href="start_con.html#cb96-13" aria-hidden="true" tabindex="-1"></a>alpn <span class="ot">&lt;-</span> <span class="fu">rep</span>(alp, <span class="at">each =</span> n)</span>
<span id="cb96-14"><a href="start_con.html#cb96-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-15"><a href="start_con.html#cb96-15" aria-hidden="true" tabindex="-1"></a>expfct <span class="ot">&lt;-</span> <span class="cf">function</span>(x, Am, alpha, Rd, theta) {(<span class="dv">1</span><span class="sc">/</span>(<span class="dv">2</span> <span class="sc">*</span> theta)) <span class="sc">*</span> (alpha <span class="sc">*</span> x <span class="sc">+</span> Am <span class="sc">-</span> <span class="fu">sqrt</span>((alpha <span class="sc">*</span> x <span class="sc">+</span> Am)<span class="sc">^</span><span class="dv">2</span> <span class="sc">-</span> <span class="dv">4</span> <span class="sc">*</span> alpha <span class="sc">*</span> theta <span class="sc">*</span> Am <span class="sc">*</span> x)) <span class="sc">-</span> Rd</span>
<span id="cb96-16"><a href="start_con.html#cb96-16" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb96-17"><a href="start_con.html#cb96-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-18"><a href="start_con.html#cb96-18" aria-hidden="true" tabindex="-1"></a>paras <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">alpha =</span> <span class="fu">rep</span>(<span class="fu">seq</span>(<span class="fl">0.01</span>, <span class="fl">0.07</span>, <span class="at">by =</span> <span class="fl">0.005</span>), <span class="at">each =</span> n), </span>
<span id="cb96-19"><a href="start_con.html#cb96-19" aria-hidden="true" tabindex="-1"></a>           <span class="at">x =</span> <span class="fu">rep</span>(lrc_Q, n), <span class="at">Am =</span> <span class="fu">rep</span>(<span class="fl">12.31</span>, n), <span class="at">Rd =</span> <span class="fu">rep</span>(<span class="fl">0.66</span>, n), </span>
<span id="cb96-20"><a href="start_con.html#cb96-20" aria-hidden="true" tabindex="-1"></a>           <span class="at">theta =</span> <span class="fu">rep</span>(<span class="fl">0.71</span>, n))</span>
<span id="cb96-21"><a href="start_con.html#cb96-21" aria-hidden="true" tabindex="-1"></a>y <span class="ot">=</span> <span class="fu">unlist</span>(<span class="fu">pmap</span>(paras, expfct))</span>
<span id="cb96-22"><a href="start_con.html#cb96-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-23"><a href="start_con.html#cb96-23" aria-hidden="true" tabindex="-1"></a>show <span class="ot">&lt;-</span> <span class="fu">data.frame</span>(<span class="at">x =</span> <span class="fu">rep</span>(lrc_Q, <span class="dv">14</span>),</span>
<span id="cb96-24"><a href="start_con.html#cb96-24" aria-hidden="true" tabindex="-1"></a>           <span class="at">y =</span> <span class="fu">c</span>(lrc_A, y), </span>
<span id="cb96-25"><a href="start_con.html#cb96-25" aria-hidden="true" tabindex="-1"></a>           <span class="at">a =</span> <span class="fu">factor</span>(<span class="fu">c</span>(<span class="fu">rep</span>(<span class="st">&quot;measured&quot;</span>, n), alpn),</span>
<span id="cb96-26"><a href="start_con.html#cb96-26" aria-hidden="true" tabindex="-1"></a>           <span class="at">level =</span> <span class="fu">c</span>(<span class="st">&quot;measured&quot;</span>, alp)</span>
<span id="cb96-27"><a href="start_con.html#cb96-27" aria-hidden="true" tabindex="-1"></a>             ))</span>
<span id="cb96-28"><a href="start_con.html#cb96-28" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb96-29"><a href="start_con.html#cb96-29" aria-hidden="true" tabindex="-1"></a><span class="fu">ggplot</span>(<span class="at">data =</span> show, <span class="fu">aes</span>(x, y, <span class="at">group =</span> a, <span class="at">color=</span>a)) <span class="sc">+</span> </span>
<span id="cb96-30"><a href="start_con.html#cb96-30" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_point</span>() <span class="sc">+</span> </span>
<span id="cb96-31"><a href="start_con.html#cb96-31" aria-hidden="true" tabindex="-1"></a>  <span class="fu">geom_smooth</span>(<span class="at">se =</span> <span class="cn">FALSE</span>) </span></code></pre></div>
<div class="figure"><span style="display:block;" id="fig:malp"></span>
<img src="bookdown_files/figure-html/malp-1.png" alt="多个 alpha 取值的差异" width="672" />
<p class="caption">
图 9.4: 多个 alpha 取值的差异
</p>
</div>
<p>从上图 <a href="start_con.html#fig:malp">9.4</a> 我们我们可以看到，实测值在 alpha =0.04 和 alpha = 0.05 两条曲线之间，在 0.045 时最接近测量点，也就是我们把初始值设为 0.04 和 0.05 之间最接近，本例中可认为是0.045，实际这三个值均可。</p>
</div>
</div>
<div id="mult_try" class="section level2" number="9.3">
<h2><span class="header-section-number">9.3</span> 自动多次尝试法</h2>
<p>该方法实际为使用 <code>nls2</code> 来实现，具体方法参考 <span class="citation">Bouvier and Huet (<a href="#ref-nls2" role="doc-biblioref">1994</a>)</span> 的文章，可简单概括为使用一系列的起始值梯度（例如下面的代码中， alpha 的取值在 0.01 到 0.08 之间 ），然后软件循序使用不同的起始值，即排列组合所有的起始值序列，最终找到合适的值，具体实现如下：</p>
<div class="sourceCode" id="cb97"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb97-1"><a href="start_con.html#cb97-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(nls2)</span>
<span id="cb97-2"><a href="start_con.html#cb97-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb97-3"><a href="start_con.html#cb97-3" aria-hidden="true" tabindex="-1"></a>grid.test <span class="ot">&lt;-</span> <span class="fu">expand.grid</span>(<span class="fu">list</span>(</span>
<span id="cb97-4"><a href="start_con.html#cb97-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">Am=</span><span class="fu">c</span>(<span class="dv">12</span>),</span>
<span id="cb97-5"><a href="start_con.html#cb97-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">alpha =</span> <span class="fu">seq</span>(<span class="fl">0.01</span>, <span class="fl">0.08</span>, <span class="at">by =</span><span class="fl">0.01</span>),</span>
<span id="cb97-6"><a href="start_con.html#cb97-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">Rd =</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">3</span>),</span>
<span id="cb97-7"><a href="start_con.html#cb97-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">theta=</span><span class="fu">seq</span>(<span class="fl">0.1</span>, <span class="dv">1</span>, <span class="at">by =</span> <span class="fl">0.1</span>)</span>
<span id="cb97-8"><a href="start_con.html#cb97-8" aria-hidden="true" tabindex="-1"></a>  ))</span>
<span id="cb97-9"><a href="start_con.html#cb97-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb97-10"><a href="start_con.html#cb97-10" aria-hidden="true" tabindex="-1"></a>lrcnls2 <span class="ot">&lt;-</span> <span class="fu">nls2</span>(lrc_A <span class="sc">~</span> </span>
<span id="cb97-11"><a href="start_con.html#cb97-11" aria-hidden="true" tabindex="-1"></a>        (<span class="dv">1</span><span class="sc">/</span>(<span class="dv">2</span><span class="sc">*</span>theta))<span class="sc">*</span></span>
<span id="cb97-12"><a href="start_con.html#cb97-12" aria-hidden="true" tabindex="-1"></a>        (alpha<span class="sc">*</span>lrc_Q<span class="sc">+</span>Am<span class="sc">-</span><span class="fu">sqrt</span>((alpha<span class="sc">*</span>lrc_Q<span class="sc">+</span>Am)<span class="sc">^</span><span class="dv">2</span> <span class="sc">-</span> </span>
<span id="cb97-13"><a href="start_con.html#cb97-13" aria-hidden="true" tabindex="-1"></a>                               <span class="dv">4</span><span class="sc">*</span>alpha<span class="sc">*</span>theta<span class="sc">*</span>Am<span class="sc">*</span>lrc_Q))<span class="sc">-</span> </span>
<span id="cb97-14"><a href="start_con.html#cb97-14" aria-hidden="true" tabindex="-1"></a>        Rd, <span class="at">start =</span> grid.test, <span class="at">algorithm =</span> <span class="st">&quot;brute-force&quot;</span>)</span></code></pre></div>
<pre><code>## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model
## Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
##   Missing value or an infinity produced when evaluating the model</code></pre>
<div class="sourceCode" id="cb99"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb99-1"><a href="start_con.html#cb99-1" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(lrcnls2)</span></code></pre></div>
<pre><code>## 
## Formula: lrc_A ~ (1/(2 * theta)) * (alpha * lrc_Q + Am - sqrt((alpha * 
##     lrc_Q + Am)^2 - 4 * alpha * theta * Am * lrc_Q)) - Rd
## 
## Parameters:
##        Estimate Std. Error t value Pr(&gt;|t|)    
## Am    12.000000   0.623023  19.261 1.27e-08 ***
## alpha  0.050000   0.006414   7.795 2.72e-05 ***
## Rd     1.000000   0.260153   3.844  0.00394 ** 
## theta  0.800000   0.102143   7.832 2.62e-05 ***
## ---
## Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Residual standard error: 0.3663 on 9 degrees of freedom
## 
## Number of iterations to convergence: 320 
## Achieved convergence tolerance: NA</code></pre>
<p>通过结果可以看到，虽然和之前采用手动方法判定的结果比较接近，但是还是略有差异，可以看一下他们各自的结果同测量值的重合程度：</p>
<div class="sourceCode" id="cb101"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb101-1"><a href="start_con.html#cb101-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(lrc_Q, lrc_A)</span>
<span id="cb101-2"><a href="start_con.html#cb101-2" aria-hidden="true" tabindex="-1"></a><span class="fu">lines</span>(lrc_Q,  <span class="fu">predict</span>(lrcnls2), <span class="at">col=</span><span class="st">&quot;red&quot;</span>)</span>
<span id="cb101-3"><a href="start_con.html#cb101-3" aria-hidden="true" tabindex="-1"></a><span class="fu">lines</span>(lrc_Q,  <span class="fu">predict</span>(lrcnls_manual), <span class="at">col=</span><span class="st">&quot;blue&quot;</span>)</span></code></pre></div>
<div class="figure"><span style="display:block;" id="fig:mcomp"></span>
<img src="bookdown_files/figure-html/mcomp-1.png" alt="两种方法结果的对比展示" width="672" />
<p class="caption">
图 9.5: 两种方法结果的对比展示
</p>
</div>
<p>图 <a href="start_con.html#fig:mcomp">9.5</a> 可以看到，使用 <code>nls2</code> 的拟合结果似乎和测量值更匹配，当然这只是第一印象，后续的判断还要进一步通过 F 检验、 AIC、BIC 等统计方式才能判定。</p>
</div>
<div id="sum_start" class="section level2" number="9.4">
<h2><span class="header-section-number">9.4</span> 小结</h2>
<p>采用如上三种方式都可以有效的解决起始值的问题，<code>nlsLM</code> 操作上更易实现，对初始值的大小不敏感，但设置不能太离谱，否则仍然会报错。作图比对法操作上更麻烦一些，但是这种方式一定能得出合理的初始值设置。采用 <code>nls2</code> 类似于将手动作图方式自动化，类似于 SPSS 中非线性拟合中需要给出一个初始值的范围，且该范围不能过大。如有一定的经验，操作起来将非常迅速。</p>
<p>需要注意的是，这三种方法结合起来使用会更好，例如，即使使用 <code>nlsLM</code> 的结果不合理，也可以参考他们参数的范围（部分结果也可能是差异显著），然后将这些结果用于手动作图判定参数或者 <code>nls2</code> 中判定参数范围，或者使用作图法确定大致的范围，将该范围输入到 <code>nls2</code> 中，这样会节省时间，也更加方便。</p>

</div>
</div>
<h3>参考文献</h3>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-nls2" class="csl-entry">
Bouvier, Annie, and Sylvie Huet. 1994. <span>“Nls2 Nonlinear Regression by s PLUS Functions.”</span> <em>Computational Statistics &amp; Data Analysis</em> 18 (1): 187–90.
</div>
<div id="ref-Elzhov2016minpack" class="csl-entry">
Elzhov, Timur V., Katharine M. Mullen, Andrej Nikolai Spiess, and Ben Bolker. 2016. <span>“Minpack.lm: R Interface to the Levenberg-Marquardt Nonlinear Least-Squares Algorithm Found in MINPACK, Plus Support for Bounds.”</span>
</div>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="lrc_fit.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="anay_6800.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": true,
"facebook": false,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"whatsapp": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/zhujiedong/photoanalysis/blob/master/11-start-values.Rmd",
"text": "编辑"
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": ["bookdown.pdf"],
"search": {
"engine": "fuse",
"options": null
},
"toc": {
"collapse": "section"
}
});
});
</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>

</html>
